home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / nehe17.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  8.0 KB  |  132 lines

  1.     dim base                 ' Base Display List For The Font
  2.     dim texture(1)           ' Storage For Our Font Texture
  3.     dim loop                 ' Generic Loop Variable
  4.  
  5.     dim cnt1#                ' 1st Counter Used To Move Text & For Coloring
  6.     dim cnt2#                ' 2nd Counter Used To Move Text & For Coloring
  7.     dim cx#                  ' Holds Our X Character Coord
  8.     dim cy#                  ' Holds Our Y Character Coord
  9.     
  10.     ' Print routine parameters
  11.     dim x, y, string$, set, i  
  12.     dim charArray(1024)
  13.                
  14.     ' Load textures
  15.     glGenTextures(2, texture)                           ' Create Two Textures
  16.     texture(0) = LoadMipmapTexture ("Data\Font.bmp")
  17.     texture(1) = LoadMipmapTexture ("Data\Bumps.bmp")
  18.  
  19.     ' Build font
  20.     base=glGenLists(256)                                ' Creating 256 Display Lists
  21.     glBindTexture(GL_TEXTURE_2D, texture(0))            ' Select Our Font Texture
  22.     for loop = 0 to 255                                 ' Loop Through All 256 Lists
  23.         cx#=(loop %16)/16.0                             ' X Position Of Current Character
  24.         cy#=(loop /16)/16.0                             ' Y Position Of Current Character
  25.  
  26.         glNewList(base+loop,GL_COMPILE)                 ' Start Building A List
  27.             glBegin(GL_QUADS)                           ' Use A Quad For Each Character
  28.                 glTexCoord2f(cx#,1-cy#-0.0625)          ' Texture Coord (Bottom Left)
  29.                 glVertex2i(0,0)                         ' Vertex Coord (Bottom Left)
  30.                 glTexCoord2f(cx#+0.0625,1-cy#-0.0625)   ' Texture Coord (Bottom Right)
  31.                 glVertex2i(16,0)                        ' Vertex Coord (Bottom Right)
  32.                 glTexCoord2f(cx#+0.0625,1-cy#)          ' Texture Coord (Top Right)
  33.                 glVertex2i(16,16)                       ' Vertex Coord (Top Right)
  34.                 glTexCoord2f(cx#,1-cy#)                 ' Texture Coord (Top Left)
  35.                 glVertex2i(0,16)                        ' Vertex Coord (Top Left)
  36.             glEnd()                                     ' Done Building Our Quad (Character)
  37.             glTranslated(10,0,0)                        ' Move To The Right Of The Character
  38.         glEndList()                                     ' Done Building The Display List
  39.     next                                                ' Loop Until All 256 Are Built
  40.  
  41.     ' Init OpenGL
  42.     glBlendFunc(GL_SRC_ALPHA,GL_ONE)                    ' Select The Type Of Blending
  43.     glShadeModel(GL_SMOOTH)                             ' Enables Smooth Color Shading
  44.     glEnable(GL_TEXTURE_2D)                             ' Enable 2D Texture Mapping
  45.     goto Start
  46.     
  47. ' Print routine
  48. glPrint:        
  49.     if set > 1 then
  50.         set = 1
  51.     endif
  52.     glBindTexture(GL_TEXTURE_2D, texture(0))            ' Select Our Font Texture
  53.     glDisable(GL_DEPTH_TEST)                            ' Disables Depth Testing
  54.     glMatrixMode(GL_PROJECTION)                         ' Select The Projection Matrix
  55.     glPushMatrix()                                      ' Store The Projection Matrix
  56.     glLoadIdentity()                                    ' Reset The Projection Matrix
  57.     glOrtho(0,640,0,480,-1,1)                           ' Set Up An Ortho Screen
  58.     glMatrixMode(GL_MODELVIEW)                          ' Select The Modelview Matrix
  59.     glPushMatrix()                                      ' Store The Modelview Matrix
  60.     glLoadIdentity()                                    ' Reset The Modelview Matrix
  61.     glTranslated(x,y,0)                                 ' Position The Text (0,0 - Bottom Left)
  62.     glListBase(base-32+(128*set))                       ' Choose The Font Set (0 or 1)    
  63.  
  64.     ' Convert string to an array of integers. (Basic4GL doesn't do the "string = array of characters" thing.)
  65.     for i = 1 to len(string$)
  66.         charArray (i - 1) = asc (mid$ (string$, i, 1))
  67.     next
  68.     glCallLists (len (string$), GL_INT, charArray)      ' Call lists
  69.     glMatrixMode(GL_PROJECTION)                         ' Select The Projection Matrix
  70.     glPopMatrix()                                       ' Restore The Old Projection Matrix
  71.     glMatrixMode(GL_MODELVIEW)                          ' Select The Modelview Matrix
  72.     glPopMatrix()                                       ' Restore The Old Projection Matrix
  73.     glEnable(GL_DEPTH_TEST)                             ' Enables Depth Testing
  74.     return
  75.     
  76. Start:
  77.     
  78.     ' Main loop
  79.     while true
  80.         
  81.         ' Render scene
  82.     glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) ' Clear The Screen And The Depth Buffer
  83.     glLoadIdentity()                                    ' Reset The Modelview Matrix
  84.     glBindTexture(GL_TEXTURE_2D, texture(1))            ' Select Our Second Texture
  85.     glTranslatef(0.0,0.0,-5.0)                          ' Move Into The Screen 5 Units
  86.     glRotatef(45.0,0.0,0.0,1.0)                         ' Rotate On The Z Axis 45 Degrees (Clockwise)
  87.     glRotatef(cnt1#*30.0,1.0,1.0,0.0)                   ' Rotate On The X & Y Axis By cnt1 (Left To Right)
  88.     glDisable(GL_BLEND)                                 ' Disable Blending Before We Draw In 3D
  89.     glColor3f(1.0,1.0,1.0)                              ' Bright White
  90.     glBegin(GL_QUADS)                                   ' Draw Our First Texture Mapped Quad
  91.         glTexCoord2d(0.0,0.0)                           ' First Texture Coord
  92.         glVertex2f(-1.0, 1.0)                           ' First Vertex
  93.         glTexCoord2d(1.0,0.0)                           ' Second Texture Coord
  94.         glVertex2f( 1.0, 1.0)                           ' Second Vertex
  95.         glTexCoord2d(1.0,1.0)                           ' Third Texture Coord
  96.         glVertex2f( 1.0,-1.0)                           ' Third Vertex
  97.         glTexCoord2d(0.0,1.0)                           ' Fourth Texture Coord
  98.         glVertex2f(-1.0,-1.0)                           ' Fourth Vertex
  99.     glEnd()                                             ' Done Drawing The First Quad
  100.     glRotatef(90.0,1.0,1.0,0.0)                         ' Rotate On The X & Y Axis By 90 Degrees (Left To Right)
  101.     glBegin(GL_QUADS)                                   ' Draw Our Second Texture Mapped Quad
  102.         glTexCoord2d(0.0,0.0)                           ' First Texture Coord
  103.         glVertex2f(-1.0, 1.0)                           ' First Vertex
  104.         glTexCoord2d(1.0,0.0)                           ' Second Texture Coord
  105.         glVertex2f( 1.0, 1.0)                           ' Second Vertex
  106.         glTexCoord2d(1.0,1.0)                           ' Third Texture Coord
  107.         glVertex2f( 1.0,-1.0)                           ' Third Vertex
  108.         glTexCoord2d(0.0,1.0)                           ' Fourth Texture Coord
  109.         glVertex2f(-1.0,-1.0)                           ' Fourth Vertex
  110.     glEnd()                                             ' Done Drawing Our Second Quad
  111.     glEnable(GL_BLEND)                                  ' Enable Blending
  112.  
  113.     glLoadIdentity()                                    ' Reset The View
  114.  
  115.     ' Pulsing Colors Based On Text Position
  116.     glColor3f(1.0*cos(cnt1#),1.0*sin(cnt2#),1.0-0.5*cos(cnt1#+cnt2#))
  117.     x = int((280+250*cos(cnt1#))): y = int(235+200*sin(cnt2#)): string$ = "NeHe": set = 0: gosub glPrint
  118.  
  119.     glColor3f(1.0*sin(cnt2#),1.0-0.5*cos(cnt1#+cnt2#),1.0*cos(cnt1#))
  120.     x = int((280+230*cos(cnt2#))): y = int(235+200*sin(cnt1#)): string$ = "OpenGL": set = 1: gosub glPrint
  121.  
  122.     glColor3f(0.0,0.0,1.0)                              ' Set Color To Blue
  123.     x = int(240+200*cos((cnt2#+cnt1#)/5)): y = 2: string$ = "Giuseppe D`Agata": set = 0: gosub glPrint
  124.  
  125.     glColor3f(1.0,1.0,1.0)                              ' Set Color To White
  126.     x = int(242+200*cos((cnt2#+cnt1#)/5)): y = 2: string$ = "Giuseppe D`Agata": set = 0: gosub glPrint
  127.     
  128.     SwapBuffers ()
  129.  
  130.     cnt1# = cnt1# + 0.01                                ' Increase The First Counter
  131.     cnt2# = cnt2# + 0.0081                              ' Increase The Second Counter
  132. wend